




/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：02/16/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/ 
package com.application.yffeereimbur.struts.actions;
import java.io.File;
import java.io.PrintWriter;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.application.attachment.entity.Attachment;
import com.application.attachment.service.AttachmentService;
import com.application.attachment.struts.form.AttachmentForm;
import com.application.usertable.entity.Usertable;
import com.application.yfexamine.entity.YfExmaine;
import com.application.yfexamine.service.YfExmaineService;
import com.application.yfexamine.struts.form.YfExmaineForm;
import com.application.yffeereimbur.commons.Constants;
import com.application.yffeereimbur.entity.YfFeeReimbur;
import com.application.yffeereimbur.service.YfFeeReimburService;
import com.application.yffeereimbur.struts.form.YfFeeReimburForm;
import com.manager.commons.ChangeRMB;
import com.manager.commons.CommonUtil;
import com.manager.commons.DisplayTagPageBean;
import com.manager.commons.RandomKey;
import com.manager.commons.page.PageBean;
import com.manager.word.FreeMarkerFactory;
import com.manager.workflow.WorkFlowConstants;
import com.manager.workflow.core.WorkFlowCommon;
import com.manager.workflow.core.YfWorkFlowDefine;
 /**
 * 
 * Description:YfFeeReimburAction<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060    <br />
 * 
 * History: <br />
 * 
 * 02/16/2012 
 * 
 */
public class YfFeeReimburAction extends DispatchAction
{
       
       /**
	 * Service层实例
	 */
	private YfFeeReimburService yfFeeReimburService;
	
	private AttachmentService attachmentService;
	
	private WorkFlowCommon workFlowCommon;
	
	private YfExmaineService yfExmaineService;

	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * 实体对象
	 */
        private YfFeeReimbur yfFeeReimbur;


        /**
	 * 采用partialList方式分页程序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward getYfFeeReimburPartialList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("searchYfFeeReimbur" + "开始");
		YfFeeReimburForm yfFeeReimbur = (YfFeeReimburForm)form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List yfFeeReimburList = null;
		resultSize = yfFeeReimburService.getAllCountYfFeeReimbur(yfFeeReimbur);
		pageBean = PageBean.getPageBean("yfFeeReimburTab", resultSize,request);
		yfFeeReimburList = yfFeeReimburService.searchYfFeeReimbur(yfFeeReimbur,pageBean);
		request.setAttribute("yfFeeReimburList", yfFeeReimburList);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelect());
		log.debug("searchYfFeeReimbur" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}

   
    
        /**
	 * 到达新增页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toAddYfFeeReimbur(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toAddYfFeeReimburs");
		YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
		yfFeeReimburForm.setId(RandomKey.generateID_Long_19());
		yfFeeReimburForm.setOrg(CommonUtil.getCurrentUser(request).getOrg());
		yfFeeReimburForm.setRname(CommonUtil.getCurrentUser(request).getRname());
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 增加
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward addYfFeeReimbur(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		 log.debug("addYfFeeReimburs");
		 YfFeeReimbur yfFeeReimbur = this.getYfFeeReimbur(form);
		 yfFeeReimbur.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_1);
		 yfFeeReimbur.setOperateid(CommonUtil.getCurrentUser(request).getId());
		 yfFeeReimbur.setCreateDate(new Date());

		this.yfFeeReimburService.insertObject(yfFeeReimbur);

		return mapping.findForward(Constants.SUCCESS);
	}
        
	/**
	 * 删除
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward deleteYfFeeReimbur(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("deleteYfFeeReimburs");
		YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
		this.yfFeeReimburService.deleteYfFeeReimburs(yfFeeReimburForm);
		String serverPath=CommonUtil.ATTACHE_FILE;
		if(StringUtils.isBlank(serverPath)){
			serverPath=request.getSession().getServletContext().getRealPath("/"); 
		}
		AttachmentForm attachmentForm = new AttachmentForm();
		attachmentForm.setFid(yfFeeReimburForm.getId().toString());
		attachmentForm.setType(com.manager.commons.Constants.FJ_TYPE_FYBX);
		List<Attachment> attachment = attachmentService.queryAttachment(attachmentForm);
		if(attachment!=null && attachment.size()>0){
			for (Attachment attachment2 : attachment) {
				File file = new File(serverPath + attachment2.getUrl());
		        file.delete();
				attachmentService.deleteObject(attachment2);
				
			}
		}
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toUpdateYfFeeReimbur(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toUpdateYfFeeReimburs");

		YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
		yfFeeReimbur = this.yfFeeReimburService.searchYfFeeReimbur(yfFeeReimburForm,null).get(0);
		request.setAttribute(Constants.YFFEEREIMBUR, yfFeeReimbur);
		return mapping.findForward(Constants.SUCCESS);
	}

        
	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updateYfFeeReimbur(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("updateYfFeeReimburs");
		YfFeeReimbur yfFeeReimbur = this.getYfFeeReimbur(form);
	    yfFeeReimbur.setOperateid(CommonUtil.getCurrentUser(request).getId());
		yfFeeReimbur.setCreateDate(new Date());
		this.yfFeeReimburService.updateObject(yfFeeReimbur);
		return mapping.findForward(Constants.SUCCESS);
	}
    
	/**
	 * 修改报销状态
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward modifyStatus(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("modifyStatus");
		YfFeeReimbur yfFeeReimbur = this.getYfFeeReimbur(form);
		yfFeeReimbur = yfFeeReimburService.getYfFeeReimbur(yfFeeReimbur);
		yfFeeReimbur.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_5);
		this.yfFeeReimburService.updateObject(yfFeeReimbur);
		return mapping.findForward(Constants.SUCCESS);
	}
	
	/**
	 * 查看页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward viewYfFeeReimbur(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("viewYfFeeReimbur");
		YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
		yfFeeReimbur = this.yfFeeReimburService.searchYfFeeReimbur(yfFeeReimburForm,null).get(0);
		request.setAttribute(Constants.YFFEEREIMBUR, yfFeeReimbur);
		String processId = yfFeeReimbur.getProcessId();
		if(StringUtils.isNotBlank(processId)){
			examineList(processId, yfExmaineService, request);
		}
	
		return mapping.findForward(Constants.SUCCESS);
	}

	// get--set
	/**
	 * @return the YfFeeReimburService
	 */
	public YfFeeReimburService getYfFeeReimburService() {
		return this.yfFeeReimburService;
	}

	/**
	 * @param YfFeeReimburService
	 *  the YfFeeReimburService to set
	 */
	public void setYfFeeReimburService(YfFeeReimburService yfFeeReimburService) {
		this.yfFeeReimburService = yfFeeReimburService;
	}

	/**
	 * 获取YfFeeReimbur实体
	 * @param ActionForm
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @return the YfFeeReimbur
	 */
	public YfFeeReimbur getYfFeeReimbur(ActionForm form) throws IllegalAccessException, InvocationTargetException {
		YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
		yfFeeReimbur = new YfFeeReimbur();
		BeanUtils.copyProperties(yfFeeReimbur, yfFeeReimburForm);
		return yfFeeReimbur;
	}
    
        public void setYfFeeReimbur(YfFeeReimbur yfFeeReimbur) {
		this.yfFeeReimbur = yfFeeReimbur;
	}

		public AttachmentService getAttachmentService() {
			return attachmentService;
		}

		public void setAttachmentService(AttachmentService attachmentService) {
			this.attachmentService = attachmentService;
		}
		/**
		 * 提交审核
		 * 
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward submitWorkFlowYfFeeReimbur(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)
				throws Exception {
			log.debug("submitWorkFlowYfFeeReimbur");
			String submitType = request.getParameter("submitType");
			//新增界面直接提交
			if(StringUtils.isNotBlank(submitType) && "add".equals(submitType)){
				yfFeeReimbur = this.getYfFeeReimbur(form);
				yfFeeReimbur.setOperateid(CommonUtil.getCurrentUser(request).getId());
				yfFeeReimbur.setCreateDate(new Date());
				this.yfFeeReimburService.insertObject(yfFeeReimbur);
			}
			if(StringUtils.isNotBlank(submitType) && "update".equals(submitType)){
				yfFeeReimbur = this.getYfFeeReimbur(form);
			}else{
				YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
				YfFeeReimburForm tempForm = new YfFeeReimburForm();
				tempForm.setId(yfFeeReimburForm.getId());
				yfFeeReimbur = this.yfFeeReimburService.searchYfFeeReimbur(tempForm,null).get(0);
			}
			Map<String,String> mapVar = new HashMap<String,String>();
			mapVar.put("bussId", yfFeeReimbur.getId().toString());
			mapVar.put("bussType", WorkFlowConstants.BUSS_TYPE_FYBX.toString());
			String proname =  yfFeeReimbur.getProjectName()==null?CommonUtil.getDictValue(yfFeeReimbur.getFeeType().intValue(), "FEE_TYPE"):yfFeeReimbur.getProjectName();
			proname = proname + "（" + yfFeeReimbur.getRname()  + "）";
			mapVar.put("projectName", proname);
			mapVar.put("projectType", yfFeeReimbur.getProjectType()==null?"0":yfFeeReimbur.getProjectType().toString());
			mapVar.put("projectOrg", yfFeeReimbur.getProjectOrg());
			mapVar.put("projectNo", yfFeeReimbur.getProjectNo());
			mapVar.put("ownYear","0");  //外协合同 暂时不放  
			CommonUtil.putMapVarFEE(request,mapVar);
			String processId = workFlowCommon.startFlow(WorkFlowConstants.PORCESS_DEFINITION_FY,CommonUtil.getCurrentUser(request).getId(),mapVar);
		
			yfFeeReimbur.setProcessId(processId);
			yfFeeReimbur.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_2);
			yfFeeReimbur.setOperateid(CommonUtil.getCurrentUser(request).getId());
			yfFeeReimbur.setCreateDate(new Date());
			this.yfFeeReimburService.updateObject(yfFeeReimbur);
			return mapping.findForward(Constants.SUCCESS);
		}

		/**
		 * 进入审核页面
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward toAuditYfFeeReimbur(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("toAuditYfFeeReimbur");
			YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
			
			String bussId = request.getParameter("bussId");
			String processId = request.getParameter("processId");
			String workItemId = request.getParameter("workItemId");
			String bussType = request.getParameter("bussType");
			String auditRole = request.getParameter("auditRole");
			yfFeeReimburForm.setId(bussId);
			yfFeeReimbur = this.yfFeeReimburService.searchYfFeeReimbur(yfFeeReimburForm,null).get(0);
			yfFeeReimbur.setWorkItemId(workItemId);
			request.setAttribute(Constants.YFFEEREIMBUR, yfFeeReimbur);
			request.setAttribute("bussType",bussType);
			request.setAttribute("auditRole", auditRole);
			examineList(processId,yfExmaineService,request);
			return mapping.findForward(Constants.SUCCESS);
		}
		
		
		/**
		 * 进入审核页面
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward staticYfFeeReimbur(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("staticYfFeeReimbur");
			YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
			yfFeeReimburForm.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_5);
			List<YfFeeReimbur> yfFeeReimburList = yfFeeReimburService.staticYfFeeReimbur(yfFeeReimburForm,null);
			request.setAttribute("yfFeeReimburList", yfFeeReimburList);
			if(yfFeeReimburList!=null){
				request.setAttribute("totalMoney", totalMoney(yfFeeReimburList));
			}
			request.setAttribute("yearSelect", CommonUtil.getYearSelect());
			request.setAttribute("orgSelect", CommonUtil.getOrgSelect());

			return mapping.findForward(Constants.SUCCESS);
		}
		
		private YfFeeReimburForm totalMoney(List<YfFeeReimbur> yfFeeReimburList){
			YfFeeReimburForm temp = new YfFeeReimburForm();
			BigDecimal amount = new BigDecimal("0");
			if(yfFeeReimburList!=null){
				for (YfFeeReimbur yfFeeReimbur : yfFeeReimburList) {
					if(yfFeeReimbur.getApplyMoney()!=null){
						amount = amount.add(yfFeeReimbur.getApplyMoney());
					}
				}
			}
			BigDecimal bd = amount.setScale(2,BigDecimal.ROUND_HALF_UP);   
			temp.setApplyMoney(bd);
			return temp;
		}
		
		/**
		 * 处理审批 提交流程
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return
		 * @throws Exception
		 */
		public ActionForward commandFlowYfFeeReimbur(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("commandFlowYfFeeReimbur");
			YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
			yfFeeReimbur = this.yfFeeReimburService.searchYfFeeReimbur(yfFeeReimburForm,null).get(0);
			YfExmaine examine = addYfExmaine(yfFeeReimburForm,request);
			Map processVar = new HashMap();
			//不为打回修改完成后提交
			if(!examine.getExamineFlag().equals("modify")){
				yfExmaineService.insertObject(examine);
				if(examine.getExamineFlag().equals(WorkFlowConstants.AUDIT_STATUS_AGREE)){
					processVar.put("approveFlag","agree");
					Usertable user = (Usertable) request.getSession().getAttribute("loginUser");
					String roleName = user.getRoleList().get(0).getName();
					if(roleName.equals(WorkFlowConstants.ROLE_FGFZ)){
						processVar.put("complete", 1);
						yfFeeReimbur.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_3);
						yfFeeReimburService.updateObject(yfFeeReimbur);
					}
				}else if(examine.getExamineFlag().equals(WorkFlowConstants.AUDIT_STATUS_DISAGREE)){
					processVar.put("approveFlag","disagree");
					yfFeeReimbur.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_4);
					yfFeeReimburService.updateObject(yfFeeReimbur);
				}
			}
			
			
			processVar.put("bussId", yfFeeReimbur.getId().toString());
			processVar.put("bussType", WorkFlowConstants.BUSS_TYPE_FYBX.toString());
			String proname =  yfFeeReimbur.getProjectName()==null?CommonUtil.getDictValue(yfFeeReimbur.getFeeType().intValue(), "FEE_TYPE"):yfFeeReimbur.getProjectName();
			proname = proname + "（" + yfFeeReimbur.getRname()  + "）";
			processVar.put("projectName", proname);
			processVar.put("projectType", yfFeeReimbur.getProjectType()==null?"0":yfFeeReimbur.getProjectType().toString());
			processVar.put("projectOrg", yfFeeReimbur.getProjectOrg());
			processVar.put("projectNo", yfFeeReimbur.getProjectNo());
			processVar.put("ownYear", "0");
			processVar.put("yfbussTaskType",WorkFlowConstants.BUSS_TASK_TYPE_NORMAL);
			/**
			 * 打回修改后需要提交  根据角色决定流程路径
			 */
			CommonUtil.putMapVarFEE(request,processVar);
			String workItemId = yfFeeReimburForm.getWorkItemId();
			if(examine.getExamineFlag().equals(WorkFlowConstants.AUDIT_STATUS_REBACK)){
				processVar.put("yfbussTaskType",WorkFlowConstants.BUSS_TASK_TYPE_REBACK);
				String operateId = yfFeeReimbur.getOperateid();
				if(CommonUtil.isZXFZR(operateId)){
					workFlowCommon.commandFlowRebackFEE(workItemId, processVar,YfWorkFlowDefine.START_ZRZXFZR);
				}else if(CommonUtil.isYFJL(operateId)){
					workFlowCommon.commandFlowRebackFEE(workItemId, processVar,YfWorkFlowDefine.START_YFJL);
				}else{
				    workFlowCommon.commandFlowRebackFEE(workItemId, processVar,YfWorkFlowDefine.START_XMJL);
				}
			}else{
				workFlowCommon.commandFlow(workItemId, processVar);
			}
			return mapping.findForward(Constants.SUCCESS);
		}
		
		/**
		 * Description: TODO 组合审批意见对象,添加
		 * 
		 * @param form
		 * @param request
		 * @return ActionForward
		 */
		public YfExmaine addYfExmaine(ActionForm form, HttpServletRequest request) {

			YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
			// 审核标识
			String examineFlag = yfFeeReimburForm.getExamineFlag();
			// 审核意见
			String examineOption = yfFeeReimburForm.getExamineOption();
			String processId = yfFeeReimburForm.getProcessId();
			YfExmaine yfExmaine = new YfExmaine();
			 
			yfExmaine.setId(RandomKey.generateID_Long_19());
			yfExmaine.setExamineFlag(examineFlag);
			yfExmaine.setExamineOption(examineOption);
			yfExmaine.setProcessId(processId);
			yfExmaine.setExamineDate(new Date());
			if(request.getSession().getAttribute("loginUser")!=null){
				Usertable curUser = (Usertable) request.getSession().getAttribute("loginUser");
				yfExmaine.setExaminePerson(curUser.getRname());
				if(curUser.getRoleList().size()>1){
					String roleName = workFlowCommon.getRoleNameByActivityId(yfFeeReimburForm.getWorkItemId(),2);
					yfExmaine.setExamineOrg(roleName);
				}else{
					yfExmaine.setExamineOrg(curUser.getRoleList().get(0).getName()); //无法处理同一个人有多个审批角色
				}
				
			}
			return yfExmaine;
		}
		
		 /*
		 * Description: TODO 查看显示意见
		 * 
		 * @param processInsId
		 * @param examine
		 * @param examineService
		 * @param examineLis
		 * @param request
		 *        void
		 */
		public void examineList(String processInsId, YfExmaineService yfExmaineService, HttpServletRequest request) throws Exception {
			YfExmaineForm yfExmaineForm = new YfExmaineForm();
			yfExmaineForm.setProcessId(processInsId);
			// 审批列表
			List<YfExmaine> examineList = yfExmaineService.searchYfExmaine(yfExmaineForm, null);
			// 防止页面出错
			int resultSize = 0;
			if(examineList != null && !examineList.isEmpty()) {
				resultSize = examineList.size();
			}
			DisplayTagPageBean.getPageBean("examine", resultSize, 0, request);
			request.setAttribute("examineList", examineList);

		}
		
		/**
		 * 到达更新页面
		 * 
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward toUpdateIncYfFeeReimbur(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("toUpdateIncYfFeeReimbur");
			String id = request.getParameter("id") == null ? "" : request.getParameter("id").toString();
			YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
			yfFeeReimburForm.setId(id);
			yfFeeReimbur = this.yfFeeReimburService.searchYfFeeReimbur(yfFeeReimburForm,null).get(0);
			request.setAttribute(Constants.YFFEEREIMBUR, yfFeeReimbur);
			return mapping.findForward(Constants.SUCCESS);
		}
		
		/**
		 * 导出
		 * 
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward exportYfFeeReimbur(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("exportYfFeeReimbur");
			List<YfExmaine> examineList = new ArrayList<YfExmaine>();
			String serverPath=request.getSession().getServletContext().getRealPath("/");
			String templetePath = serverPath + "/templete";
			String fileName = new String("费用报销单".getBytes("gb2312"), "ISO8859-1");
			YfFeeReimburForm yfFeeReimburForm = (YfFeeReimburForm) form;
			yfFeeReimbur = this.yfFeeReimburService.searchYfFeeReimbur(yfFeeReimburForm,null).get(0);
			request.setAttribute(Constants.YFFEEREIMBUR, yfFeeReimbur);
			String processId = yfFeeReimbur.getProcessId();
			if(StringUtils.isNotBlank(processId)){
				YfExmaineForm yfExmaineForm = new YfExmaineForm();
				yfExmaineForm.setProcessId(processId);
				// 审批列表
				examineList = yfExmaineService.searchYfExmaine(yfExmaineForm, null);
			}
			Map mapValue = new HashMap();
			if(yfFeeReimbur.getApplyMoney()!=null){
				ChangeRMB cr = new ChangeRMB();
				String bigMoney = cr.convertToChineseNumber(yfFeeReimbur.getApplyMoney().doubleValue());
				yfFeeReimbur.setBigMoney(bigMoney);
				yfFeeReimbur.setSmallMoney(String.valueOf(yfFeeReimbur.getApplyMoney().doubleValue()));
			}
			mapValue.put("yfFeeReimbur", yfFeeReimbur);
			mapValue.put("examineList", examineList);
			FreeMarkerFactory factory = FreeMarkerFactory.getInstance(templetePath);
			response.addHeader("Content-Disposition", "attachment;filename=" + "baoxiao" + ".doc");
			response.setContentType("application/application msword; charset=utf-8");
			request.setCharacterEncoding("UTF-8"); 
			response.setHeader("Pragma", "no-cache");
			Writer out = response.getWriter();
			factory.processTemplete(mapValue, "baoxiao.ftl", out);
			return null;
		}

		
		/**
		 * 更新
		 * 
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward updateIncYfFeeReimbur(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("updateIncYfApplyCost");
			String id = request.getParameter("id") == null ? "" : request.getParameter("id").toString();
			YfFeeReimbur yfFeeReimbur = this.getYfFeeReimbur(form);
			yfFeeReimbur.setOperateid(CommonUtil.getCurrentUser(request).getId());
			yfFeeReimbur.setCreateDate(new Date());
			this.yfFeeReimburService.updateObject(yfFeeReimbur);
			PrintWriter out = response.getWriter();
			out.print("<script>window.opener.document.location.reload(); self.close();</script>");
			return null;
		}



		public WorkFlowCommon getWorkFlowCommon() {
			return workFlowCommon;
		}



		public void setWorkFlowCommon(WorkFlowCommon workFlowCommon) {
			this.workFlowCommon = workFlowCommon;
		}



		public YfExmaineService getYfExmaineService() {
			return yfExmaineService;
		}



		public void setYfExmaineService(YfExmaineService yfExmaineService) {
			this.yfExmaineService = yfExmaineService;
		}
}
